// const
//     dns = require('dns'),
//     socks5 = require('../dist/socks5'),
//     server = socks5.createServer({
//         connectionFilter : function (destination, origin, callback) {
//             console.log('Attempting to connect to...');
//             console.log(destination);
//             console.log();
//             console.log('Inbound origin of request is...');
//             console.log(origin);
//
//             return dns.reverse(destination.address, function (err, hostnames) {
//                 if (!hostnames || !hostnames.length || !/github/.test(hostnames[0])) {
//                     console.log('Not allowing connection to %s:%s', destination.address, destination.port);
//
//                     return callback(new Error('connection to destination address is denied (only github is allowed)'));
//                 }
//
//                 return callback();
//             });
//
//         }
//     });
//
// server.on('connectionFilter', function (destination, origin, err) {
//     console.log('connection to %s:%s has been denied (only requests to github are allowed)', destination.address, destination.port);
//     console.error(err);
// });
//
// // start listening!
// server.listen(1080);

const
    socks5 = require('simple-socks'),
    server = socks5.createServer().listen(1080);

// When a reqest arrives for a remote destination
server.on('proxyConnect', function (info, destination) {
    console.log('connected to remote server at %s:%d', info.address, info.port);

    destination.on('data', function (data) {
        console.log(data.length);
    });
});

// When data arrives from the remote connection
server.on('proxyData', function (data) {
    console.log(data.length);
});

// When an error occurs connecting to remote destination
server.on('proxyError', function (err) {
    console.error('unable to connect to remote server');
    console.error(err);
});

// When a proxy connection ends
server.on('proxyEnd', function (response, args) {
    console.log('socket closed with code %d', response);
    console.log(args);
});